home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc / Environment Additions / Symantec / Additions / SOM (SPM) / somcmpat.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-10-27  |  8.4 KB  |  292 lines  |  [TEXT/MPS ]

  1. /************************************************************
  2.  
  3. Created: Friday, March 24, 1995 at 3:12:00 PM
  4.     somcmpat.h
  5.     
  6.     System Object Model
  7.     Macintosh Version
  8.  
  9.         © International Business Machines Corp. 1992-1994
  10.         © Apple Computer, Inc.                    1994-1995
  11.         All rights reserved
  12.  
  13. ************************************************************/
  14.  
  15.  
  16. #ifndef        __SOMCMPAT__
  17. #define        __SOMCMPAT__
  18.  
  19. #include <som.h>
  20.  
  21. #if __IBM_TO_MAC__
  22.  
  23. /* 
  24.  *
  25.  *    The compatibility header for porting code from the standard
  26.  *    SOM API to the modern SOM APIs.  This file defines older API
  27.  *    functions as macros so that their use does not cause
  28.  *    compile time errors.  Given no changes to the ported
  29.  *    source code, these macros implement the best possible equivalent
  30.  *    in terms of the existing APIs.
  31.  *
  32.  */
  33.  
  34. /* included by som.h */
  35.  
  36. typedef char integer1;
  37. typedef short integer2;
  38. typedef unsigned short uinteger2;
  39. typedef long integer4;
  40. typedef unsigned long uinteger4;
  41. typedef float float4;
  42. typedef double float8;
  43. typedef char *zString;                    /* NULL terminated string */
  44. typedef char *fString;                    /* non-terminated string  */
  45. typedef corbastring string;
  46.  
  47. /* define private macro to obtain class object */
  48. #ifdef    __cplusplus
  49.  #define SOM_GetClass(obj) \
  50.     ( ( obj ) -> somGetClass () )
  51. #else
  52.  #define SOM_GetClass(obj) \
  53.     _somGetClass ( obj )
  54. #endif
  55.  
  56. /* define the class manager global */
  57. SOMEXTERN SOMClassMgr SOMSTAR SOMClassMgrObject;
  58.  
  59. /* add dual usage for somEnvironmentNew */
  60. #define somEnvironmentNew() (somEnvironmentNew(),SOMClassMgrObject)
  61.  
  62. #define somWriteMetrics(fp,z)    ((void) ((fp),(z)))
  63. #define somSaveMetrics()        ((void) 0)
  64. #define somPrintNameSpace()        ((void) 0)
  65.  
  66. /*  -------------------------------------------------------------------
  67.  *  The following macros are for purposes of backward compatibility
  68.  *  with prior versions of SOM.  There is no advantage to using them
  69.  *  over a direct call to the corresponding routine.
  70.  */
  71.  
  72. #define SOM_CompareValidIds(id1,id2) \
  73.     (somCompareIds(id1,id2))
  74.  
  75. #define SOM_CompareIds(id1,id2) \
  76.     (somCompareIds(id1,id2))
  77.  
  78. #define SOM_IdFromString(str) \
  79.     somIdFromString(str)
  80.  
  81. #define SOM_StringFromId(id) \
  82.     somMakeStringFromId(id)
  83.  
  84. #define SOM_CheckId(id) \
  85.     (somCheckId(id))
  86.  
  87. #ifdef __cplusplus     
  88. #define SOM_SubstituteClass(old,new) \
  89.     SOMClassMgrObject -> somSubstituteClass \
  90.     ( _##old->somGetName (), _##new->somGetName ());
  91.  
  92.  
  93. #else
  94. #define SOM_SubstituteClass(old,new) \
  95.     _somSubstituteClass ( SOMClassMgrObject, \
  96.     _somGetName (_##old), _somGetName (_##new));
  97. #endif
  98.  
  99. #elif __MAC_TO_IBM__
  100.  
  101. /* 
  102.  *
  103.  *    The compatibility header for porting code from the modern
  104.  *    SOM API to other SOM APIs.  This file defines newer API
  105.  *    functions as macros so that their use does not cause
  106.  *    compile time errors.  Given no changes to the underlying
  107.  *    kernel, these macros implement the best possible equivalent
  108.  *    in terms of the existing APIs.
  109.  *
  110.  */
  111.  
  112. /* included by som.h */
  113. #include <string.h>
  114.  
  115.  
  116. /* === ID Section === */
  117.  
  118. /* a "somKernelId" is a kernel owned "somId" and can be
  119.     converted to a "somId" using the functions below */
  120. typedef somId somKernelId;
  121.  
  122. /* converts a "somKernelId" into a "somId" which must
  123.     later be freed by "SOMFree" */
  124. #define somConvertAndFreeKernelId(kernelId) \
  125.     somIdFromString ( somStringFromId ( (somId) ( kernelId ) ) )
  126.  
  127. /* frees a "somKernelId" on kernels which don't maintain
  128.     internal string databases */
  129. #define somFreeKernelId(kernelId) \
  130.     ( (void) ( kernelId ) )
  131.  
  132. /* creates a user owned "SOMMalloc'd" copy of the id string
  133.     which must later be freed by "SOMFree" */
  134. #define somMakeStringFromId(id) \
  135.     strcpy ( (char*) SOMMalloc ( strlen ( somStringFromId ( id ) ) + 1 ), \
  136.         somStringFromId ( id ) )
  137.  
  138.  
  139. /* === Dynamic Loading / Unloading Section === */
  140.  
  141. /* the API to obtain a static class object reference */
  142. #define    somNewClassReference(cls) \
  143.      ( cls ## NewClass ( cls ## _MajorVersion, cls ## _MinorVersion ) )
  144.  
  145. /* the API to obtain a static class reference that allows use of 
  146.     version numbers other than the compile time current ones */
  147. #define somNewVersionedClassReference(cls,majorVersion,minorVersion) \
  148.     ( cls ## NewClass ( majorVersion, minorVersion ) )
  149.  
  150. /* the API to get a dynamic reference w/o using the class manager */
  151. #ifdef    __cplusplus
  152. #define    somGetDynamicClassReference(classId,majorVersion,minorVersion,file) \
  153.     ( ( file ) ? SOMClassMgrObject -> somFindClsInFile (classId, majorVersion, minorVersion, file) :
  154.         SOMClassMgrObject -> somFindClass (classId, majorVersion, minorVersion) )
  155. #else
  156. #define    somGetDynamicClassReference(classId,majorVersion,minorVersion,file) \
  157.     ( ( file ) ? _somFindClsInFile ( SOMClassMgrObject, classId, majorVersion, minorVersion, file) :
  158.         _somFindClass ( SOMClassMgrObject, classId, majorVersion, minorVersion) )
  159. #endif
  160.  
  161. /* the API to release a class reference w/o destroying the class from other users */
  162. #define    somReleaseClassReference(classObject) \
  163.     ( (void) ( classObject ) )
  164.  
  165. /* === Automatic Object Allocation Section === */
  166. #ifdef    __cplusplus
  167. #define somGetInstanceSizeAndStaticClassReference(cls,majorVersion,minorVersion,classObj) \
  168.     (( *classObj = cls ## NewClass ( majorVersion, minorVersion ) ) -> somGetInstanceSize ())
  169. #else
  170. #define somGetInstanceSizeAndStaticClassReference(cls,majorVersion,minorVersion,classObj) \
  171.     _somGetInstanceSize ( *classObj = cls ## NewClass ( majorVersion, minorVersion ) )
  172. #endif
  173.  
  174. #ifdef    __cplusplus
  175. #define somInitInstanceAndFreeClassReference(classObject,addr) \
  176.     ( ( classObject ) -> somRenew ( addr ) )
  177. #else
  178. #define somInitInstanceAndFreeClassReference(classObject,addr) \
  179.     _somRenew ( classObject, addr )
  180. #endif
  181.  
  182. #ifdef    __cplusplus
  183. #define somDestructAutoObject(obj) \
  184.     ( ( obj ) -> somUninit () )
  185. #else
  186. #define somDestructAutoObject(obj) \
  187.     _somUninit ( obj )
  188. #endif
  189.  
  190.  
  191. /* === Class Manager Section === */
  192.  
  193. /* the API to obtain a reference to the class manager */
  194. #define    somGetClassManagerReference() \
  195.     SOMClassMgrObject
  196.  
  197. /* the API to release a reference to a class manager object */
  198. #define    somReleaseClassManagerReference(classMgrObj) \
  199.     ( (void) ( classMgrObj ) )
  200.  
  201.  
  202. /* === Init / Term Section === */
  203.  
  204. /* the API to inform SOM of the existance of a class w/o obtaining
  205.     a reference to the class object */
  206. #define somNewClass(cls) \
  207.     (( void ) cls ## NewClass ( cls ## _MajorVersion, cls ## _MinorVersion ))
  208.  
  209. /* the API to inform SOM of the impending demise of a class
  210.     (ie: the code for it is about to be unloaded) */
  211. #define somKillClass(cls)    /* ignore */
  212.  
  213.  
  214. /* === Object Creation Section === */
  215.  
  216. /* the API to obtain a new instance object w/o having
  217.     to deal with the class object */
  218. #ifdef    __cplusplus
  219. #define somNewObject(cls) \
  220.     new cls
  221. #else
  222. #define somNewObject(cls) \
  223.     cls ## New()
  224. #endif
  225.  
  226. /* the API to obtain a new instance object w/o having
  227.     to deal with the class object, but with version
  228.     checking other than the compile time current numbers */
  229. #ifdef    __cplusplus
  230. #define somNewVersionedObject(cls, majorVersion, minorVersion) \
  231.     ((cls SOMSTAR) (( cls ## NewClass ( majorVersion, minorVersion ) ) \
  232.                 -> somNew ()))
  233. #else
  234. #define somNewVersionedObject(cls, majorVersion, minorVersion) \
  235.     ((cls SOMSTAR) _somNew ( cls ## NewClass ( majorVersion, minorVersion ) ))
  236. #endif
  237.  
  238. #ifdef    __cplusplus
  239. inline SOMObject SOMSTAR somNewObjectById ( somId classId,
  240.     long majorVersion, long minorVersion )
  241. {
  242.     SOMClass SOMSTAR classObj = SOMClassMgrObject -> somFindClass
  243.         ( classId, majorVersion, minorVersion );
  244.     return classObj ? classObj -> somNew () : NULL;
  245. }
  246. #else
  247. static SOMObject SOMSTAR somNewObjectById ( somId classId,
  248.     long majorVersion, long minorVersion )
  249. {
  250.     SOMClass SOMSTAR classObj = _somFindClass ( SOMClassMgrObject,
  251.         classId, majorVersion, minorVersion );
  252.     return classObj ? _somNew ( classObj ) : NULL;
  253. }
  254. #endif
  255.  
  256. static SOMObject SOMSTAR somNewObjectByName ( corbastring className, 
  257.     long majorVersion, long minorVersion )
  258. {
  259.     SOMObject SOMSTAR obj = NULL;
  260.     somId classId = somIdFromString ( className );
  261.     if ( classId ) {
  262.         obj = somNewObjectById ( classId, majorVersion, minorVersion );
  263.         SOMFree ( classId );
  264.     }
  265.     return obj;
  266. }
  267.  
  268. #define somDuplicateReference(obj) \ 
  269.     ((SOMObject SOMSTAR) (obj))
  270.  
  271. #define somCompareReference(ob1j,obj2) \
  272.     ((void *) (obj1) == (void *) (obj2))
  273.  
  274. /* the API to release a reference to an object w/o
  275.     destroying the object for others that are using it */
  276. #if RELEASE_MEANS_FREE
  277.  #ifdef    __cplusplus
  278.   #define somReleaseObjectReference(obj) \
  279.     (( obj ) -> somFree ())
  280.  #else
  281.   #define somReleaseObjectReference(obj) \
  282.     ( _somFree ( obj ) )
  283.  #endif
  284. #else
  285.  #define somReleaseObjectReference(obj) \
  286.     ( (void) ( obj ) )
  287. #endif
  288.  
  289. #endif    /* __MAC_TO_IBM__ */
  290.  
  291. #endif    /* __SOMCMPAT__ */
  292.